﻿using System.Collections.Generic;
using System.Linq;

namespace Game.Plugin.Parse
{
    public class Number : IExpression 
    {
        readonly int _Number;

        public Number(int number) 
        { 
            _Number = number; 
        }

        public object Interpret(Dictionary<string, ICodeObject> variables)
        {
            return _Number;
        }
    }

    public class NumberParser : IParser
    {
        public bool CanParse(string data)
        {
            return data.Length > 0 && data.All(char.IsDigit);
        }

        public ICodeObject Parse(
            string token, 
            ParserContext context)
        {
            IExpression e = new Number(int.Parse(token));
            context.Stack.Push(e);
            return e;
        }

    }
}
